/* eslint-disable max-lines */
import DataSelect from '@/components/DataSelect';
import TauSimpleSelect from '@/components/TauSimpleSelect';
import { ellipsisRender } from '@/components/TauTable';
import * as BASE from '@/stores/definitions-base';
import { DatePicker2, Input, List, Switch, Tag } from '@alifd/next';
import { t } from '@lingui/macro';
import dayjs from 'dayjs';
import React from 'react';

const {
  DATETIME_TEXT,
  DATE_TEXT,
  TIME_TEXT,
  EMPTY_TEXT,
  ENUMS: ENUMSBase,
  FieldsGrid: FieldGridBase,
  TitleGrid,
  column: columnBase,
  toSelectDataSource,
} = BASE;
export { DATETIME_TEXT, DATE_TEXT, EMPTY_TEXT, TIME_TEXT, TitleGrid, toSelectDataSource };

export function column(...args) {
  return columnBase(orderModel, ...args);
}

export function FieldsGrid(props) {
  return <FieldGridBase model={orderModel} {...props} />;
}

//----------------------------------------------------------------------
export const ENUMS = {
  ...ENUMSBase,
};

export const orderModel = {
  fullname: {
    label: t`下单人`,
  },
  changeId: {
    label: t`订单号`,
    text: (v, r) => {
      const { newInfo, oldInfo } = r;
      return <>{`${oldInfo.id} >> ${newInfo.id}`}</>;
    },
  },
  changePrice: {
    label: t`价格`,
    text: (v, r) => {
      const { newInfo, oldInfo } = r;
      return <>{`${oldInfo.price.toFixed(2)} >> ${newInfo.price.toFixed(2)}`}</>;
    },
  },
  changeCrDate: {
    label: t`下单时间`,
    text: (v, r) => {
      const { newInfo, oldInfo } = r;
      return <>{`${oldInfo.crDate} >> ${newInfo.crDate}`}</>;
    },
  },
  content: {
    label: t`改签内容`,
    text: (v, r) => {
      const { content = {} } = r;
      const tmpContent = Object.entries(content).map(([_, value]) => (value));
      return (
        <>{JSON.stringify(content) !== '{}' ? ellipsisRender(tmpContent.map((p, i) => (
          <div key={p}>
            <span>{`${i + 1}: ${p}`}</span>
            <br />
          </div>
        ))) : <>{t`该订单未做任何改签内容`}</>}
        </>
      );
    },
    changeFromStation: {
      label: t`上车站点`,
    },
    changeToStation: {
      label: t`下车站点`,
    },
    changeReturnFromStation: {
      label: t`回程上车站点`,
    },
    changeReturnToStation: {
      label: t`回程下车站点`,
    },
  },
  newInfo: {
    id: {
      label: t`新订单号`,
    },
    price: {
      label: t`新订单价格`,
    },
    crDate: {
      label: t`新订单下单时间`,
    },
  },
  oldInfo: {
    id: {
      label: t`旧订单号`,
    },
    price: {
      label: t`旧订单价格`,
    },
    crDate: {
      label: t`旧订单下单时间`,
    },
  },
  changeTickets: {
    label: t`关联的车票`,
    text: (v, r) => {
      return (
        <>{v.map((p, i) => {
          return (
            <div key={`${p.ticketCode}-${i}`}>
              <span>{p.ticketCode}</span>
              <br />
            </div>
          );
        })}
        </>
      );
    },
  },
};

